<#include "./template/general_temp.ftl">

<#macro content>
<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-posts"></i>稿件管理</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content">
                <div class="alert alert-info box col-md-12">
                    <div class="box col-md-6">
                        <a class="btn btn-success" href="${base}/system/posts/addAuthorPosts?from=moke"><i class="glyphicon glyphicon-plus icon-white"></i>新增</a>
                    </div>
                    <div class="box col-md-6">
                        <form class="form-inline" role="form">
                            <div class="form-group">
                                <select id="status" class="form-control">
                                    <option value="待审核">待审核</option>
                                    <option value="审核通过">审核通过</option>
                                    <option value="审核不通过">审核不通过</option>
                                </select>
                            </div>
                            <button type="button" onclick="queryData()" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
                        </form>
                    </div>
                </div>
                <table id="posts_dg">
                </table>
            </div>
        </div>
    </div>
    <!--/span-->

</div><!--/row-->
</#macro>

<#macro script>
<script type="text/javascript">
    function getQueryCondition(){
        var status = $("#status").val();
        return {"statuses":status};
    }

    function queryData(){
        var pars=getQueryCondition();
        //构造列表
        jQuery('#posts_dg').datagrid({
            url:'${base}/system/posts/verifyList',
            fitColumns : true,
            striped : true,
            pagination : true,
            rownumbers : true,
            pageSize : 20,
            pageNumber : 1,
            pageList : [ 20, 50],
            loadMsg : '数据正在加载中...',
            singleSelect:true,
            queryParams : pars,
            selectOnCheck : false,
            checkOnSelect : false,
            width:$('.box-content').width() * 0.985,
            columns : [[
                {field : 'postTitle', title : '标题',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center',
                    formatter:function(value,row,index) {
                        return "<a href='${base}/system/posts/edit?from=moke&id=" + row.id + "'>" + row.postTitle +"</a>";
                    }
                },
                {field : 'postAuthorStr', title : '专栏作者',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.1, align: 'center'},
                {field : 'createTimeStr', title : '提交时间',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'postStatus', title : '状态',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'extra1', title : '最后操作人',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'ctrl', title : '操作',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center',
                    formatter:function(value,row,index) {
                        if (row.postStatus == "待审核") {
                            var confirm = "<a class='btn btn-info' href='javascript:void(0)' onclick='audit(" + row.id + ",1)'><i class='glyphicon glyphicon-edit icon-white'></i>同意</a>";
                            var refuse = "<a class='btn btn-primary' href='javascript:void(0)' onclick='audit(" + row.id + ",0)'><i class='glyphicon glyphicon-trash icon-white'></i>拒绝</a>"

                            return confirm + refuse;
                        }else{
                            return "";
                        }
                    }
                }
            ]],
            onLoadSuccess:function(data){
            },
            onClickRow: function (rowIndex, rowData) {

            }
        });
    }

    function audit(id,confirm){
        if(window.confirm("确认同意吗？")){
            jQuery.ajax({
                type: "POST",
                url: base + '/system/posts/verify',
                dataType:"json",
                data: {"id": id,"confirm":confirm},
                success: function(data){
                    if(data.status == 1) {
                        alert("操作成功！");
                        queryData();
                    }else{
                        alert("操作失败！");
                    }
                },
                error: function (obj){
                    console.info(obj);
                }
            });
        }
    }

    $(document).ready(function () {
        queryData();
    });

</script>
</#macro>
